package com.gps.funnymath.abstractItems;

import com.gps.funnymath.concreteItems.ConcreteNumber;
import com.gps.funnymath.concreteItems.ConcreteToken;
import com.gps.funnymath.domains.NumberDomain;


public class AbstractNumber implements AbstractToken{

	NumberDomain numberDomain;
	ConcreteToken lastConcreteToken;
	
	public AbstractNumber(NumberDomain numberDomain){
		this.numberDomain = numberDomain;
		lastConcreteToken = null;
	}
	
	public ConcreteToken instantiate(){
		lastConcreteToken = numberDomain.getRandom();
		return lastConcreteToken;
	}
	
	@Override
	public ConcreteToken getLastInstantiation() {
		return lastConcreteToken;
	}
	
	@Override
	public ConcreteToken getConcreteToken() {
		if(lastConcreteToken != null)
			return lastConcreteToken;

		return instantiate();
	}
	
	public ConcreteNumber getConcreteNumber(){
		return (ConcreteNumber)getConcreteToken();
	}
	
	@Override
	public void clearInstantiationReferences() {
		lastConcreteToken = null;
	}
}
